package com.china.produce.service.audio.impl;

import com.china.produce.factorys.audio.AudioRequestFactory;
import com.china.produce.service.audio.AudioService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

/**
 * @ClassName
 * @Author niujie
 * @Version
 * @Description
 * @CreateTime 2023/6/15
 */
@Service
@Slf4j
public class AudioServiceImpl implements AudioService, ApplicationContextAware{

    private ApplicationContext applicationContext;

    public AudioRequestFactory getAudioRequestFactoryBeanByType(String type) {

        AudioRequestFactory factoryBean = null;
        if ("ali".equals(type)) {
             factoryBean = (AudioRequestFactory) applicationContext.getBean("aliAudioRequestFactoryBean");
        }else if ("tencent".equals(type)) {
             factoryBean = (AudioRequestFactory) applicationContext.getBean("tencentAudioRequestFactoryBean");
        }else {
            log.info("cuo");
        }

        return factoryBean;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

        this.applicationContext = applicationContext;
    }
}
